import Opt from '@/components/dt/info/Opt.js'
import table from '@/components/dt/table/render.js'

class Column extends Opt {
  constructor(vm, name) {
    super()
    this.vm = vm
    this.name = name
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        field: 'menuName',
        title: this.name != '3' ? '菜单名称' : '模块名称'
      },
      {
        field: 'menuCode',
        title: '菜单code'
      },
      {
        field: 'menuIcon',
        title: '菜单图标',
        visible: this.name != '3',
        slots: {
          default: (params, h) => {
            let img = {
              src: params.row.menuIcon,
              data: [params.row.menuIcon]
            }
            return params.row.menuIcon ? table.cell.img(this.vm, h, img) : []
          }
        }
      },
      {
        field: 'sort',
        title: '菜单权重'
      },
      {
        title: '操作',
        width: this.name != '3' ? 200 : 100,
        fixed: 'right',
        cell: (row) => {
          return {
            group: [
              {
                visible: this.vm.unlocking('0214010200'),
                button: {
                  type: 'text',
                  title: '编辑',
                  ghost: true,
                  style: { color: 'blue', marginTop: '-10px' },
                  click: () => {
                    this.vm.onEdit(row)
                  }
                }
              },
              {
                visible: this.name != '3',
                switch: {
                  type: 'text',
                  openText: 'New',
                  closeText: 'New',
                  size: 'large'
                },
                data: {
                  from: (info) => info.mark == 1,
                  to: (res) => ({ mark: res ? 1 : 0 })
                },
                change: (res) => {
                  this.vm.onMark(res.info)
                }
              },
              {
                visible: this.name != '3',
                switch: {
                  type: 'text',
                  openText: 'Hot',
                  closeText: 'Hot',
                  size: 'large'
                },
                data: {
                  from: (info) => info.mark == 2,
                  to: (res) => ({ mark: res ? 2 : 0 })
                },
                change: (res) => {
                  this.vm.onMark(res.info)
                }
              }
            ]
          }
        }
      }
    ]
  }
}

export default Column
